package com.engine.action;

import com.engine.core.util.Response;
import com.engine.service.DbDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/api/db")
public class DbOperateAction {

    @Autowired
    private DbDataService dbDataService;

    @RequestMapping(value = "/{action}",method = {RequestMethod.POST,RequestMethod.GET})
    public String query(@Autowired HttpServletRequest request, @Autowired HttpServletResponse response,@PathVariable("action") String action){
        Response res=dbDataService.query(request,response,action);
        return res.getJSONString();
    }

    @PutMapping
    public String put(@Autowired HttpServletRequest request, @Autowired HttpServletResponse response){
        Response res=dbDataService.putSave(request,response);
        return res.getJSONString();
    }
    @DeleteMapping
    public String delete(@Autowired HttpServletRequest request, @Autowired HttpServletResponse response){
        Response res=dbDataService.delete(request,response);
        return res.getJSONString();
    }
}
